﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FIFP.Common;
using FIFP.DashBoard.Helper;
using System.Collections.Generic;
using Telerik.Windows.Controls.ScheduleView;
using FIFP.DashBoard.Model;
using Telerik.Windows.Controls;
using System.Linq;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using FIFP.DashBoard.Views;
using FIFP.DashBoard.Converters;
using System.Linq.Expressions;
using System.Collections;
using System.Threading;
using EffectiveCapacityReport;
using FIFP.DashBoard.RelationalDataService;
using System.IO;
using System.Xml;
using System.Xml.Linq;

namespace FIFP.DashBoard.ViewModel
{
    public class ImportVM : ViewModelCore, INotifyPropertyChanged, INotifyDataErrorInfo
    {
        #region Variables
        public event EventHandler<CustomEventArgs<AppointmentGroup>> OnAppointmentDataCompleted;
        public event EventHandler<CustomEventArgs<List<string>>> OnDivisionListDataCompleted;
        private readonly ICollection<ValidationResult> _validationResults;
        private bool isOpenRawData = false;
        private bool isOpenBaseScenario = false;
        CreateScenarioPopup scenarioPopup;
        OpenScenarioPopup openScenarioPopup;
        private BusyIndicator busyIndicator;
        Report reportWindow;
        #endregion

        #region Properties

        private List<string> divisionList = new List<string>();
        public List<string> DivisionList
        {
            get { return divisionList; }
            set { SetPropertyValue(() => DivisionList, value, val => divisionList = val); }
        }

        private Style _OpenRawDataStyle = Application.Current.Resources[FIFPConstants.BUTTON_DEFAULTCOLOR] as Style;
        public Style OpenRawDataStyle
        {
            get { return _OpenRawDataStyle; }
            set { SetPropertyValue(() => OpenRawDataStyle, value, val => _OpenRawDataStyle = val); }
        }

        private Style _OpenBaseScenarioStyle = Application.Current.Resources[FIFPConstants.BUTTON_DEFAULTCOLOR] as Style;
        public Style OpenBaseScenarioStyle
        {
            get { return _OpenBaseScenarioStyle; }
            set { SetPropertyValue(() => OpenBaseScenarioStyle, value, val => _OpenBaseScenarioStyle = val); }
        }

        private Style _ScenarioStyle = Application.Current.Resources[FIFPConstants.BUTTON_DEFAULTCOLOR] as Style;
        public Style ScenarioStyle
        {
            get { return _ScenarioStyle; }
            set { SetPropertyValue(() => ScenarioStyle, value, val => _ScenarioStyle = val); }
        }

        private Style _SaveAsStyle = Application.Current.Resources[FIFPConstants.BUTTON_DEFAULTCOLOR] as Style;
        public Style SaveAsStyle
        {
            get { return _SaveAsStyle; }
            set { SetPropertyValue(() => SaveAsStyle, value, val => _SaveAsStyle = val); }
        }

        private Style _SaveStyle = Application.Current.Resources[FIFPConstants.BUTTON_DEFAULTCOLOR] as Style;
        public Style SaveStyle
        {
            get { return _SaveStyle; }
            set { SetPropertyValue(() => SaveStyle, value, val => _SaveStyle = val); }
        }


        private Resource selectedUnit;
        public Resource SelectedUnit
        {
            get { return selectedUnit; }
            set
            {
                if (selectedUnit != value)
                {
                    selectedUnit = value;
                    OnPropertyChanged(() => this.SelectedUnit);
                    OnPropertyChanged(() => this.FilterUnitValue);
                }
            }
        }

        private string selectedDivision;
        public string SelectedDivision
        {
            get { return selectedDivision; }
            set
            {
                if (selectedDivision != value)
                {
                    selectedDivision = value;
                    OnPropertyChanged(() => this.SelectedDivision);
                }
            }
        }



        private bool isSaveEnabled = false;
        public bool IsSaveEnabled
        {
            get { return isSaveEnabled; }
            set { SetPropertyValue(() => IsSaveEnabled, value, val => isSaveEnabled = val); }
        }

        private bool isSaveAsEnabled = false;
        public bool IsSaveAsEnabled
        {
            get { return isSaveAsEnabled; }
            set { SetPropertyValue(() => IsSaveAsEnabled, value, val => isSaveAsEnabled = val); }
        }

        private List<FIFPAppointment> importPlans = new List<FIFPAppointment>();
        public List<FIFPAppointment> ImportPlans
        {
            get { return importPlans; }
            set { SetPropertyValue(() => ImportPlans, value, val => importPlans = val); }
        }

        private List<FIFPAppointment> scenarioPlans = new List<FIFPAppointment>(); //We are using this list for caching the user's scenario data
        public List<FIFPAppointment> ScenarioPlans
        {
            get { return scenarioPlans; }
            set { SetPropertyValue(() => ScenarioPlans, value, val => scenarioPlans = val); }
        }

        private Dictionary<int, FIFPAppointment> originalPlansDictionary = new Dictionary<int, FIFPAppointment>();
        public Dictionary<int, FIFPAppointment> OriginalPlansDictionary
        {
            get { return originalPlansDictionary; }
            set { SetPropertyValue(() => OriginalPlansDictionary, value, val => originalPlansDictionary = val); }
        }

        private bool isBaseScenarioEnabled = true;
        public bool IsBaseScenarioEnabled
        {
            get { return isBaseScenarioEnabled; }
            set { SetPropertyValue(() => IsBaseScenarioEnabled, value, val => isBaseScenarioEnabled = val); }
        }

        private bool isBaseScenario = false;
        public bool IsBaseScenario
        {
            get { return isBaseScenario; }
            set { SetPropertyValue(() => IsBaseScenario, value, val => isBaseScenario = val); }
        }

        private bool isScenarioExist = false;
        public bool IsScenarioExist
        {
            get { return isScenarioExist; }
            set { SetPropertyValue(() => IsScenarioExist, value, val => isScenarioExist = val); }
        }

        private string _ScenarioName = string.Empty;
        [Display(Name = FIFPConstants.DISPLAY_SCENARIO)]
        [CustomValidation(typeof(ErrorValidation), FIFPConstants.VALIDATE_SCENARIO)]
        public string ScenarioName
        {
            get { return _ScenarioName; }
            set
            {
                if (_ScenarioName != value)
                {
                    _ScenarioName = value;
                    OnPropertyChanged(() => this._ScenarioName);
                }
            }
        }

        private List<Scenario> scenarioList = new List<Scenario>();
        public List<Scenario> ScenarioList
        {
            get { return scenarioList; }
            set { SetPropertyValue(() => ScenarioList, value, val => scenarioList = val); }
        }

        private int selectedScenarioId;
        public int SelectedScenarioId
        {
            get { return selectedScenarioId; }
            set { SetPropertyValue(() => SelectedScenarioId, value, val => selectedScenarioId = val); }
        }

        private Visibility _FilterVisibility = Visibility.Collapsed;
        public Visibility FilterVisibility
        {
            get { return _FilterVisibility; }
            set { SetPropertyValue(() => FilterVisibility, value, val => _FilterVisibility = val); }
        }

        private Visibility _FilterTreeVisibility = Visibility.Collapsed;
        public Visibility FilterTreeVisibility
        {
            get { return _FilterTreeVisibility; }
            set { SetPropertyValue(() => FilterTreeVisibility, value, val => _FilterTreeVisibility = val); }
        }

        private string _UnitName = string.Empty;
        [Display(Name = FIFPConstants.DISPLAY_UNITNAME)]
        [CustomValidation(typeof(ErrorValidation), FIFPConstants.VALIDATE_UNITNAME)]
        public string UnitName
        {
            get { return _UnitName; }
            set
            {
                if (_UnitName != value)
                {
                    _UnitName = value;
                    OnPropertyChanged(() => this._UnitName);
                }
            }
        }

        private bool isUnitNameExist = false;
        public bool IsUnitNameExist
        {
            get { return isUnitNameExist; }
            set { SetPropertyValue(() => IsUnitNameExist, value, val => isUnitNameExist = val); }
        }

        private bool _IsFilterButtonEnabled = false;
        public bool IsFilterButtonEnabled
        {
            get { return _IsFilterButtonEnabled; }
            set { SetPropertyValue(() => IsFilterButtonEnabled, value, val => _IsFilterButtonEnabled = val); }
        }

        private List<Unit> unitList = new List<Unit>();
        public List<Unit> UnitList
        {
            get { return unitList; }
            set { SetPropertyValue(() => UnitList, value, val => unitList = val); }
        }

        private List<Unit> treeViewUnitList = new List<Unit>();
        public List<Unit> TreeViewUnitList
        {
            get { return treeViewUnitList; }
            set { SetPropertyValue(() => TreeViewUnitList, value, val => treeViewUnitList = val); }
        }

        private List<FIFPAppointment> linkedShutdownList = new List<FIFPAppointment>();
        public List<FIFPAppointment> LinkedShutdownList
        {
            get { return linkedShutdownList; }
            set { SetPropertyValue(() => LinkedShutdownList, value, val => linkedShutdownList = val); }
        }


        private ObservableCollection<MenuItem> openMenuItems = new ObservableCollection<MenuItem>();
        public ObservableCollection<MenuItem> OpenMenuItems
        {
            get { return openMenuItems; }
            set { SetPropertyValue(() => OpenMenuItems, value, val => openMenuItems = val); }
        }

        #endregion

        #region Commands

        private ICommand _BasicScenarioCommand;
        public ICommand BasicScenarioCommand
        {
            get
            {
                return _BasicScenarioCommand ??
                        (_BasicScenarioCommand = new RelayCommand<Button>(OpenBasicScenario));
            }
        }

        private ICommand _ScenarioCommand;
        public ICommand ScenarioCommand
        {
            get
            {
                return _ScenarioCommand ??
                        (_ScenarioCommand = new RelayCommand<Button>(OpenScenario));
            }
        }

        private ICommand _SaveCommand;
        public ICommand SaveCommand
        {
            get
            {
                return _SaveCommand ??
                        (_SaveCommand = new RelayCommand<Button>(SaveScenario));
            }
        }

        private ICommand _CalculateCommand;
        public ICommand CalculateCommand
        {
            get
            {
                return _CalculateCommand ??
                        (_CalculateCommand = new RelayCommand<Button>(Calculate));
            }
        }

        private ICommand _SaveAsCommand;
        public ICommand SaveAsCommand
        {
            get
            {
                return _SaveAsCommand ??
                        (_SaveAsCommand = new RelayCommand<Button>(SaveAsScenario));
            }
        }

        private ICommand _ImportPageLoadCommand;
        public ICommand ImportPageLoadCommand
        {
            get
            {
                return _ImportPageLoadCommand ??
                        (_ImportPageLoadCommand = new RelayCommand<Grid>(LoadappointmentsFromDB));
            }
        }

        private ICommand _BusyIndicatorLoadCommand;
        public ICommand BusyIndicatorLoadCommand
        {
            get
            {
                return _BusyIndicatorLoadCommand ??
                        (_BusyIndicatorLoadCommand = new RelayCommand<BusyIndicator>(InitBusyIndicator));
            }
        }

        private ICommand _LoadOriginalPlansEvent;
        public ICommand LoadOriginalPlansEvent
        {
            get
            {
                return _LoadOriginalPlansEvent ??
                        (_LoadOriginalPlansEvent = new RelayCommand<Button>(LoadOriginalPlansFromDB));
            }
        }

        private ICommand _WarningCommand;
        public ICommand WarningCommand
        {
            get
            {
                return _WarningCommand ??
                        (_WarningCommand = new RelayCommand<Button>(ShowPopup));
            }
        }

        private ICommand _CancelCommand;
        public ICommand CancelCommand
        {
            get { return _CancelCommand ?? (_CancelCommand = new RelayCommand<Button>(HidePopup)); }
        }

        private ICommand _OpenScenarioPopupEvent;
        public ICommand OpenScenarioPopupEvent
        {
            get { return _OpenScenarioPopupEvent ?? (_OpenScenarioPopupEvent = new RelayCommand<Button>(OpenCurrentUserScenario)); }
        }

        private ICommand _SelectedScenarioCommand;
        public ICommand SelectedScenarioCommand
        {
            get { return _SelectedScenarioCommand ?? (_SelectedScenarioCommand = new RelayCommand<RadioButton>(SelectedOpenScenario)); }
        }

        private ICommand _FilterButtonVisibilityCommand;
        public ICommand FilterButtonVisibilityCommand
        {
            get
            {
                return _FilterButtonVisibilityCommand ??
                        (_FilterButtonVisibilityCommand = new RelayCommand<RadioButton>(DoFilterButtonVisibility));
            }
        }

        private ICommand _UnitFilterCommand;
        public ICommand UnitFilterCommand
        {
            get
            {
                return _UnitFilterCommand ??
                        (_UnitFilterCommand = new RelayCommand<Button>(FilterByUnitName));
            }
        }

        #endregion

        #region Constructor
        public ImportVM()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                _validationResults = new List<ValidationResult>();
                ServiceLocator.Get<MainPageVM>().OnImportClick += new EventHandler(ImportVM_OnImportClick);
                BuildUnitList();

                MenuItem planMenuItem = new MenuItem() { Text = "Plan" };
                ObservableCollection<MenuItem> pSubmenu = new ObservableCollection<MenuItem>() { };
                pSubmenu.Add(new MenuItem() {Text = "Original Plan" });
                pSubmenu.Add(new MenuItem() { Text = "Integrated Plan"});
                planMenuItem.SubItems = pSubmenu;

                MenuItem scenarioItem = new MenuItem() { Text = "Scenario" };
                ObservableCollection<MenuItem> sSubmenu = new ObservableCollection<MenuItem>() { };
                sSubmenu.Add(new MenuItem() { Text = "My Scenario" });
                sSubmenu.Add(new MenuItem() { Text = "Others" });
                scenarioItem.SubItems = sSubmenu;
                OpenMenuItems.Add(planMenuItem);
                OpenMenuItems.Add(scenarioItem);

            }
        }

        void ImportVM_OnImportClick(object sender, EventArgs e)
        {
            LoadTimelineView(ImportPlans);
        }
        #endregion

        #region Get the unit list from databse
        private void BuildUnitList()
        {
            UnitList.Add(new Unit() { ParentUnitID = -1, UnitID = 0, UnitName = "Radial12", UnitType = "Radial", FluidType = FIFPConstants.FLUIDTYPE_OIL });
            UnitList.Add(new Unit() { ParentUnitID = 0, UnitID = 1, UnitName = "Tower 12", UnitType = "Tower", FluidType = FIFPConstants.FLUIDTYPE_OIL });

            UnitList.Add(new Unit() { ParentUnitID = 1, UnitID = 1001, UnitName = "Well-137", UnitType = "Well", FluidType = FIFPConstants.FLUIDTYPE_GAS });
            UnitList.Add(new Unit() { ParentUnitID = 1, UnitID = 1002, UnitName = "Well-122", UnitType = "Well", FluidType = FIFPConstants.FLUIDTYPE_WATER });
            UnitList.Add(new Unit() { ParentUnitID = 1001, UnitID = 1003, UnitName = "String-1", UnitType = "String", FluidType = FIFPConstants.FLUIDTYPE_WATER });
            UnitList.Add(new Unit() { ParentUnitID = 1002, UnitID = 1004, UnitName = "String-2", UnitType = "String", FluidType = FIFPConstants.FLUIDTYPE_OIL });

            UnitList.Add(new Unit() { ParentUnitID = 1, UnitID = 2, UnitName = "Pipeline-1", UnitType = "Pipeline", FluidType = FIFPConstants.FLUIDTYPE_OIL });
            UnitList.Add(new Unit() { ParentUnitID = 1, UnitID = 3, UnitName = "Pipeline-2", UnitType = "Pipeline", FluidType = FIFPConstants.FLUIDTYPE_WATER });
            UnitList.Add(new Unit() { ParentUnitID = 2, UnitID = 4, UnitName = "UT-137", UnitType = "Tower", FluidType = FIFPConstants.FLUIDTYPE_COMBINED });

            UnitList.Add(new Unit() { ParentUnitID = 4, UnitID = 41, UnitName = "US-137", UnitType = "Well", FluidType = FIFPConstants.FLUIDTYPE_OIL });
            UnitList.Add(new Unit() { ParentUnitID = 41, UnitID = 411, UnitName = "String-US", UnitType = "String", FluidType = FIFPConstants.FLUIDTYPE_OIL });
            UnitList.Add(new Unit() { ParentUnitID = 4, UnitID = 42, UnitName = "PL-UT137", UnitType = "Pipeline", FluidType = FIFPConstants.FLUIDTYPE_OIL });

            UnitList.Add(new Unit() { ParentUnitID = 3, UnitID = 5, UnitName = "UT-32", UnitType = "Tower", FluidType = FIFPConstants.FLUIDTYPE_OIL });

            UnitList.Add(new Unit() { ParentUnitID = 5, UnitID = 51, UnitName = "US-4", UnitType = "Well", FluidType = FIFPConstants.FLUIDTYPE_OIL });
            UnitList.Add(new Unit() { ParentUnitID = 51, UnitID = 52, UnitName = "String-3", UnitType = "String", FluidType = FIFPConstants.FLUIDTYPE_WATER });

            UnitList.Add(new Unit() { ParentUnitID = 4, UnitID = 6, UnitName = "Pipeline-3", UnitType = "Pipeline", FluidType = FIFPConstants.FLUIDTYPE_WATER });
            UnitList.Add(new Unit() { ParentUnitID = 4, UnitID = 7, UnitName = "Pipeline-4", UnitType = "Pipeline", FluidType = FIFPConstants.FLUIDTYPE_OIL });
            UnitList.Add(new Unit() { ParentUnitID = 5, UnitID = 8, UnitName = "Pipeline-5", UnitType = "Pipeline", FluidType = FIFPConstants.FLUIDTYPE_GAS });
            UnitList.Add(new Unit() { ParentUnitID = 6, UnitID = 9, UnitName = "UT-137A", UnitType = "Tower", FluidType = FIFPConstants.FLUIDTYPE_WATER });

            UnitList.Add(new Unit() { ParentUnitID = 9, UnitID = 91, UnitName = "US-148", UnitType = "Well", FluidType = FIFPConstants.FLUIDTYPE_GAS });

            UnitList.Add(new Unit() { ParentUnitID = 91, UnitID = 93, UnitName = "String-4", UnitType = "String", FluidType = FIFPConstants.FLUIDTYPE_OIL });
            UnitList.Add(new Unit() { ParentUnitID = 92, UnitID = 94, UnitName = "String-5", UnitType = "String", FluidType = FIFPConstants.FLUIDTYPE_WATER });

            UnitList.Add(new Unit() { ParentUnitID = 7, UnitID = 10, UnitName = "Tower-5", UnitType = "Tower", FluidType = FIFPConstants.FLUIDTYPE_OIL });

            UnitList.Add(new Unit() { ParentUnitID = 10, UnitID = 101, UnitName = "Well-8", UnitType = "Well", FluidType = FIFPConstants.FLUIDTYPE_WATER });
            UnitList.Add(new Unit() { ParentUnitID = 101, UnitID = 102, UnitName = "String-6", UnitType = "String", FluidType = FIFPConstants.FLUIDTYPE_OIL });

            UnitList.Add(new Unit() { ParentUnitID = 10, UnitID = 103, UnitName = "Pipeline-7", UnitType = "Pipeline", FluidType = FIFPConstants.FLUIDTYPE_OIL });

            UnitList.Add(new Unit() { ParentUnitID = 8, UnitID = 11, UnitName = "Tower-6", UnitType = "Tower", FluidType = FIFPConstants.FLUIDTYPE_WATER });

            UnitList.Add(new Unit() { ParentUnitID = 11, UnitID = 111, UnitName = "Well-9", UnitType = "Well", FluidType = FIFPConstants.FLUIDTYPE_OIL });
            UnitList.Add(new Unit() { ParentUnitID = 11, UnitID = 112, UnitName = "Well-10", UnitType = "Well", FluidType = FIFPConstants.FLUIDTYPE_WATER });

            UnitList.Add(new Unit() { ParentUnitID = 9, UnitID = 12, UnitName = "Pipeline-6", UnitType = "Pipeline", FluidType = FIFPConstants.FLUIDTYPE_OIL });
            UnitList.Add(new Unit() { ParentUnitID = 12, UnitID = 13, UnitName = "Tower-7", UnitType = "Tower", FluidType = FIFPConstants.FLUIDTYPE_WATER });

            UnitList.Add(new Unit() { ParentUnitID = 13, UnitID = 131, UnitName = "Well-11", UnitType = "Well", FluidType = FIFPConstants.FLUIDTYPE_OIL });
            UnitList.Add(new Unit() { ParentUnitID = 13, UnitID = 132, UnitName = "Well-12", UnitType = "Well", FluidType = FIFPConstants.FLUIDTYPE_WATER });
            UnitList.Add(new Unit() { ParentUnitID = 131, UnitID = 133, UnitName = "String-7", UnitType = "String", FluidType = FIFPConstants.FLUIDTYPE_OIL });
            UnitList.Add(new Unit() { ParentUnitID = 132, UnitID = 134, UnitName = "String-8", UnitType = "String", FluidType = FIFPConstants.FLUIDTYPE_WATER });

            foreach (Unit unit in UnitList.Where(s => s.UnitType == FIFPConstants.UNITTYPE_RADIAL))
            {
                GeUnitNameList(UnitList.Where(p => p.UnitID == unit.UnitID).ToList(), 0);
            }
        }
        #endregion

        #region Get Treeview UnitList
        private void GeUnitNameList(List<Unit> lstUnits, int level)
        {
            foreach (Unit unit in lstUnits)
            {
                unit.Level = level;
                unit.ChildUnitList = UnitList.Where(p => p.ParentUnitID == unit.UnitID).ToList();
                GeUnitNameList(unit.ChildUnitList, level + 1);
            }
        }
        #endregion

        #region Make database call to get appointments
        private void LoadappointmentsFromDB(Grid layoutRoot)
        {
            if (ImportPlans != null && ImportPlans.Count == 0)
            {
                AppointmentGroup appointmentGroup = new AppointmentGroup();
                appointmentGroup.Appointments = new List<FIFPAppointment>() { new FIFPAppointment() { Subject = "ADMA" } };

                if (OnAppointmentDataCompleted != null)
                    OnAppointmentDataCompleted(this, new CustomEventArgs<AppointmentGroup>(appointmentGroup));
            }
        }
        #endregion

        #region Methods
        public Predicate<IAppointment> FilterUnitValue
        {
            get { return UnitFilter; }
        }
        public bool UnitFilter(IAppointment appt)
        {
            FIFPAppointment app = appt as FIFPAppointment;
            return app != null && FilterByUnit(app);
        }
        public bool FilterByUnit(FIFPAppointment app)
        {
            if (SelectedUnit != null && SelectedUnit.DisplayName == "Division")
                return true;
            else
                return SelectedUnit == null ||
                app.Resources.Contains(SelectedUnit);
        }

        public Predicate<IAppointment> FilterValue
        {
            get { return Filter; }
        }
        public bool Filter(IAppointment appt)
        {
            FIFPAppointment app = appt as FIFPAppointment;
            return app != null && FilterByDivision(app);
        }
        public bool FilterByDivision(FIFPAppointment app)
        {
            if (SelectedDivision != null && SelectedDivision == "Division")
                return true;
            else
                return (SelectedDivision == null || (app.Division == SelectedDivision));
        }

        private void InitBusyIndicator(BusyIndicator bI)
        {
            busyIndicator = bI;
        }

        #endregion

        #region Load Appointments
        private void LoadOriginalPlansFromDB(Button btnOriginal)
        {
            isOpenRawData = true;
            isOpenBaseScenario = false;
            IsBaseScenarioEnabled = true;
            ChangeSelectedButtonStyle(btnOriginal);
            LoadOriginalPlansToScheduleView();
        }

        private void LoadOriginalPlansToScheduleView()
        {
            List<FIFPAppointment> lstAppointments = new List<FIFPAppointment>();

            FIFPAppointment appointment1 = new FIFPAppointment();
            appointment1.PlanID = 1;
            appointment1.ActivityCode = "MTN-MM";
            appointment1.Subject = "MTN-MM";
            appointment1.UnitStatus = "CM";
            appointment1.Division = "Drilling";
            appointment1.UnitName = "Radial12";
            appointment1.UnitID = 0;
            appointment1.UnitType = "Radial";
            appointment1.ActivityType = "InstallDevice";
            appointment1.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment1.OriginalStart = appointment1.Start = DateTime.Now;
            appointment1.OriginalEnd = appointment1.End = DateTime.Now.AddDays(15);

            FIFPAppointment appointment111 = new FIFPAppointment();
            appointment111.PlanID = 111;
            appointment111.ActivityCode = "MTN-MM";
            appointment111.Subject = "MTN-MM";
            appointment111.UnitStatus = "CM";
            appointment111.Division = "Maintenance";
            appointment111.UnitName = "Radial12";
            appointment111.UnitID = 0;
            appointment111.UnitType = "Radial";
            appointment111.ActivityType = "InstallDevice";
            appointment111.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment111.OriginalStart = appointment111.Start = DateTime.Now.AddDays(10);
            appointment111.OriginalEnd = appointment111.End = DateTime.Now.AddDays(20);

            FIFPAppointment appointment112 = new FIFPAppointment();
            appointment112.PlanID = 112;
            appointment112.ActivityCode = "MTN-MM";
            appointment112.Subject = "MTN-MM";
            appointment112.UnitStatus = "CM";
            appointment112.Division = "Drilling";
            appointment112.UnitName = "Radial12";
            appointment112.UnitID = 0;
            appointment112.UnitType = "Radial";
            appointment112.ActivityType = "InstallDevice";
            appointment112.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment112.OriginalStart = appointment112.Start = DateTime.Now.AddDays(15);
            appointment112.OriginalEnd = appointment112.End = DateTime.Now.AddDays(30);



            lstAppointments.Add(appointment1);
            lstAppointments.Add(appointment111);
            lstAppointments.Add(appointment112);

            FIFPAppointment appointment2 = new FIFPAppointment();
            appointment2.PlanID = 2;
            appointment2.ActivityCode = "MTN-MM";
            appointment2.Subject = "MTN-MM";
            appointment2.UnitStatus = "CM";
            appointment2.Division = "Maintenance";
            appointment2.UnitName = "Tower 12";
            appointment2.UnitID = 1;
            appointment2.UnitType = "Tower";
            appointment2.ActivityType = "InstallDevice";
            appointment2.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment2.OriginalStart = appointment2.Start = DateTime.Now.AddDays(5);
            appointment2.OriginalEnd = appointment2.End = DateTime.Now.AddDays(15);

            FIFPAppointment appointment222 = new FIFPAppointment();
            appointment222.PlanID = 222;
            appointment222.ActivityCode = "MTN-MM";
            appointment222.Subject = "MTN-MM";
            appointment222.UnitStatus = "CM";
            appointment222.Division = "Maintenance";
            appointment222.UnitName = "Tower 12";
            appointment222.UnitID = 1;
            appointment222.UnitType = "Tower";
            appointment222.ActivityType = "InstallDevice";
            appointment222.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment222.OriginalStart = appointment222.Start = DateTime.Now.AddDays(12);
            appointment222.OriginalEnd = appointment222.End = DateTime.Now.AddDays(25);

            FIFPAppointment appointment223 = new FIFPAppointment();
            appointment223.PlanID = 223;
            appointment223.ActivityCode = "MTN-MM";
            appointment223.Subject = "MTN-MM";
            appointment223.UnitStatus = "CM";
            appointment223.Division = "Maintenance";
            appointment223.UnitName = "Tower 12";
            appointment223.UnitID = 1;
            appointment223.UnitType = "Tower";
            appointment223.ActivityType = "InstallDevice";
            appointment223.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment223.OriginalStart = appointment223.Start = DateTime.Now.AddDays(30);
            appointment223.OriginalEnd = appointment223.End = DateTime.Now.AddDays(40);

            lstAppointments.Add(appointment2);
            lstAppointments.Add(appointment222);
            lstAppointments.Add(appointment223);


            FIFPAppointment appointment3 = new FIFPAppointment();
            appointment3.PlanID = 3;
            appointment3.ActivityCode = "RIG";
            appointment3.Subject = "RIG";
            appointment3.UnitStatus = "CD";
            appointment3.Division = "Drilling";
            appointment3.UnitName = "Well-137";
            appointment3.UnitID = 1001;
            appointment3.UnitType = "Well";
            appointment3.ActivityType = "RIG";
            appointment3.FluidType = FIFPConstants.FLUIDTYPE_GAS;
            appointment3.OriginalStart = appointment3.Start = new DateTime(2012, 12, 22);
            appointment3.OriginalEnd = appointment3.End = new DateTime(2013, 01, 06);

            FIFPAppointment appointment31 = new FIFPAppointment();
            appointment31.PlanID = 31;
            appointment31.ActivityCode = "RIG";
            appointment31.Subject = "RIG";
            appointment31.UnitStatus = "CD";
            appointment31.Division = "Drilling";
            appointment31.UnitName = "Well-137";
            appointment31.UnitID = 1001;
            appointment31.UnitType = "Well";
            appointment31.ActivityType = "RIG";
            appointment31.FluidType = FIFPConstants.FLUIDTYPE_GAS;
            appointment31.OriginalStart = appointment31.Start = DateTime.Now.AddDays(10);
            appointment31.OriginalEnd = appointment31.End = DateTime.Now.AddDays(20);


            lstAppointments.Add(appointment3);
            lstAppointments.Add(appointment31);


            FIFPAppointment appointment4 = new FIFPAppointment();
            appointment4.PlanID = 4;
            appointment4.ActivityCode = "MTN-MM";
            appointment4.Subject = "MTN-MM";
            appointment4.UnitStatus = "CM";
            appointment4.Division = "Maintenance";
            appointment4.UnitName = "Well-122";
            appointment4.UnitID = 1002;
            appointment4.UnitType = "Well";
            appointment4.ActivityType = "InstallDevice";
            appointment4.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment4.OriginalStart = appointment4.Start = DateTime.Now.AddMonths(-4);
            appointment4.OriginalEnd = appointment4.End = DateTime.Now.AddMonths(-2);

            FIFPAppointment appointment41 = new FIFPAppointment();
            appointment41.PlanID = 41;
            appointment41.ActivityCode = "MTN-MM";
            appointment41.Subject = "MTN-MM";
            appointment41.UnitStatus = "CM";
            appointment41.Division = "Maintenance";
            appointment41.UnitName = "Well-122";
            appointment41.UnitID = 1002;
            appointment41.UnitType = "Well";
            appointment41.ActivityType = "InstallDevice";
            appointment41.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment41.OriginalStart = appointment41.Start = DateTime.Now.AddDays(50);
            appointment41.OriginalEnd = appointment41.End = DateTime.Now.AddDays(60);


            lstAppointments.Add(appointment4);
            lstAppointments.Add(appointment41);

            FIFPAppointment appointment5 = new FIFPAppointment();
            appointment5.PlanID = 5;
            appointment5.ActivityCode = "RIG";
            appointment5.Subject = "RIG";
            appointment5.UnitStatus = "CD";
            appointment5.Division = "Drilling";
            appointment5.UnitName = "String-1";
            appointment5.UnitID = 1003;
            appointment5.UnitType = "String";
            appointment5.ActivityType = "RIG";
            appointment5.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment5.OriginalStart = appointment5.Start = DateTime.Now.AddMonths(1);
            appointment5.OriginalEnd = appointment5.End = DateTime.Now.AddMonths(2);

            //FIFPAppointment appointment555 = new FIFPAppointment();
            //appointment555.PlanID = 555;
            //appointment555.ActivityCode = "RIG";
            //appointment555.Subject = "RIG";
            //appointment555.UnitStatus = "CD";
            //appointment555.Division = "Drilling";
            //appointment555.UnitName = "String-2";
            //appointment555.UnitID = 1004;
            //appointment555.UnitType = "String";
            //appointment555.ActivityType = "RIG";
            //appointment555.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            //appointment555.OriginalStart = appointment555.Start = DateTime.Now.AddMonths(1);
            //appointment555.OriginalEnd = appointment555.End = DateTime.Now.AddMonths(2);

            lstAppointments.Add(appointment5);
            //lstAppointments.Add(appointment555);

            FIFPAppointment appointment6 = new FIFPAppointment();
            appointment6.PlanID = 6;
            appointment6.ActivityCode = "RGL";
            appointment6.Subject = "RGL";
            appointment6.UnitStatus = "CD";
            appointment6.Division = "Maintenance";
            appointment6.UnitName = "Pipeline-1";
            appointment6.UnitID = 2;
            appointment6.UnitType = "Pipeline";
            appointment6.ActivityType = "InstallDevice";
            appointment6.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment6.OriginalStart = appointment6.Start = DateTime.Now.AddDays(30);
            appointment6.OriginalEnd = appointment6.End = DateTime.Now.AddDays(40);

            FIFPAppointment appointment61 = new FIFPAppointment();
            appointment61.PlanID = 61;
            appointment61.ActivityCode = "RGL";
            appointment61.Subject = "RGL";
            appointment61.UnitStatus = "CD";
            appointment61.Division = "Maintenance";
            appointment61.UnitName = "Pipeline-1";
            appointment61.UnitID = 2;
            appointment61.UnitType = "Pipeline";
            appointment61.ActivityType = "InstallDevice";
            appointment61.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment61.OriginalStart = appointment61.Start = DateTime.Now.AddDays(25);
            appointment61.OriginalEnd = appointment61.End = DateTime.Now.AddDays(35);


            FIFPAppointment appointment62 = new FIFPAppointment();
            appointment62.PlanID = 62;
            appointment62.ActivityCode = "RGL";
            appointment62.Subject = "RGL";
            appointment62.UnitStatus = "CD";
            appointment62.Division = "Maintenance";
            appointment62.UnitName = "Pipeline-1";
            appointment62.UnitID = 2;
            appointment62.UnitType = "Pipeline";
            appointment62.ActivityType = "InstallDevice";
            appointment62.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment62.OriginalStart = appointment62.Start = DateTime.Now.AddDays(50);
            appointment62.OriginalEnd = appointment62.End = DateTime.Now.AddDays(60);


            lstAppointments.Add(appointment6);
            lstAppointments.Add(appointment61);
            lstAppointments.Add(appointment62);

            FIFPAppointment appointment7 = new FIFPAppointment();
            appointment7.PlanID = 7;
            appointment7.ActivityCode = "MTN-MM";
            appointment7.Subject = "MTN-MM";
            appointment7.UnitStatus = "CM";
            appointment7.Division = "Maintenance";
            appointment7.UnitName = "UT-137";
            appointment7.UnitID = 4;
            appointment7.UnitType = "Tower";
            appointment7.ActivityType = "InstallDevice";
            appointment7.FluidType = FIFPConstants.FLUIDTYPE_COMBINED;
            appointment7.OriginalStart = appointment7.Start = DateTime.Now.AddDays(7);
            appointment7.OriginalEnd = appointment7.End = DateTime.Now.AddDays(13);

            FIFPAppointment appointment71 = new FIFPAppointment();
            appointment71.PlanID = 71;
            appointment71.ActivityCode = "MTN-MM";
            appointment71.Subject = "MTN-MM";
            appointment71.UnitStatus = "CM";
            appointment71.Division = "Maintenance";
            appointment71.UnitName = "UT-137";
            appointment71.UnitID = 4;
            appointment71.UnitType = "Tower";
            appointment71.ActivityType = "InstallDevice";
            appointment71.FluidType = FIFPConstants.FLUIDTYPE_COMBINED;
            appointment71.OriginalStart = appointment71.Start = DateTime.Now.AddDays(15);
            appointment71.OriginalEnd = appointment71.End = DateTime.Now.AddDays(23);

            FIFPAppointment appointment72 = new FIFPAppointment();
            appointment72.PlanID = 72;
            appointment72.ActivityCode = "PIG-IP";
            appointment72.Subject = "PIG-IP";
            appointment72.UnitStatus = "CM";
            appointment72.Division = "Maintenance";
            appointment72.UnitName = "UT-137";
            appointment72.UnitID = 4;
            appointment72.UnitType = "Tower";
            appointment72.ActivityType = "InstallDevice";
            appointment72.FluidType = FIFPConstants.FLUIDTYPE_COMBINED;
            appointment72.OriginalStart = appointment72.Start = DateTime.Now.AddDays(20);
            appointment72.OriginalEnd = appointment72.End = DateTime.Now.AddDays(40);


            lstAppointments.Add(appointment7);
            lstAppointments.Add(appointment71);
            lstAppointments.Add(appointment72);

            FIFPAppointment appointment8 = new FIFPAppointment();
            appointment8.PlanID = 8;
            appointment8.ActivityCode = "MTN-SS";
            appointment8.Subject = "MTN-SS";
            appointment8.UnitStatus = "CD";
            appointment8.Division = "Brown Fields";
            appointment8.UnitName = "Pipeline-2";
            appointment8.UnitID = 3;
            appointment8.UnitType = "Pipeline";
            appointment8.ActivityType = "MTN-SS";
            appointment8.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment8.OriginalStart = appointment8.Start = new DateTime(2012, 12, 22);
            appointment8.OriginalEnd = appointment8.End = new DateTime(2013, 01, 16);

            FIFPAppointment appointment81 = new FIFPAppointment();
            appointment81.PlanID = 81;
            appointment81.ActivityCode = "RIG";
            appointment81.Subject = "RIG";
            appointment81.UnitStatus = "CD";
            appointment81.Division = "Brown Fields";
            appointment81.UnitName = "Pipeline-2";
            appointment81.UnitID = 3;
            appointment81.UnitType = "Pipeline";
            appointment81.ActivityType = "RIG";
            appointment81.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment81.OriginalStart = appointment81.Start = DateTime.Now.AddDays(30);
            appointment81.OriginalEnd = appointment81.End = DateTime.Now.AddDays(40);

            

            lstAppointments.Add(appointment8);
            lstAppointments.Add(appointment81);

            FIFPAppointment appointment9 = new FIFPAppointment();
            appointment9.PlanID = 9;
            appointment9.ActivityCode = "INSP-F";
            appointment9.Subject = "INSP-F";
            appointment9.UnitStatus = "CU";
            appointment9.Division = "Integrity";
            appointment9.UnitName = "US-137";
            appointment9.UnitID = 41;
            appointment9.UnitType = "Well";
            appointment9.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment9.ActivityType = "InstallDevice";
            appointment9.OriginalStart = appointment9.Start = DateTime.Now.AddDays(30);
            appointment9.OriginalEnd = appointment9.End = DateTime.Now.AddDays(40);

            FIFPAppointment appointment91 = new FIFPAppointment();
            appointment91.PlanID = 91;
            appointment91.ActivityCode = "INSP-F";
            appointment91.Subject = "INSP-F";
            appointment91.UnitStatus = "CU";
            appointment91.Division = "Integrity";
            appointment91.UnitName = "US-137";
            appointment91.UnitID = 41;
            appointment91.UnitType = "Well";
            appointment91.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment91.ActivityType = "InstallDevice";
            appointment91.OriginalStart = appointment91.Start = DateTime.Now.AddDays(32);
            appointment91.OriginalEnd = appointment91.End = DateTime.Now.AddDays(50);

            
            FIFPAppointment appointment921 = new FIFPAppointment();
            appointment921.PlanID = 921;
            appointment921.ActivityCode = "PIP-IP";
            appointment921.Subject = "PIP-IP";
            appointment921.UnitStatus = "CU";
            appointment921.Division = "Integrity";
            appointment921.UnitName = "String-US";
            appointment921.UnitID = 411;
            appointment921.UnitType = "String";
            appointment921.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment921.ActivityType = "InstallDevice";
            appointment921.OriginalStart = appointment921.Start = DateTime.Now.AddDays(10);
            appointment921.OriginalEnd = appointment921.End = DateTime.Now.AddDays(20);

            lstAppointments.Add(appointment9);
            lstAppointments.Add(appointment91);
            lstAppointments.Add(appointment921);


            FIFPAppointment appointment11 = new FIFPAppointment();
            appointment11.PlanID = 11;
            appointment11.ActivityCode = "PIG-IP";
            appointment11.Subject = "PIG-IP";
            appointment11.UnitStatus = "CZ";
            appointment11.Division = "CPLD";
            appointment11.UnitName = "PL-UT137";
            appointment11.UnitID = 42;
            appointment11.UnitType = FIFPConstants.UNITTYPE_PIPELINE;
            appointment11.ActivityType = "InstallDevice";
            appointment11.FluidType = FIFPConstants.FLUIDTYPE_GAS;
            appointment11.OriginalStart = appointment11.Start = DateTime.Now.AddDays(15);
            appointment11.OriginalEnd = appointment11.End = DateTime.Now.AddDays(20);

            FIFPAppointment appointment1112 = new FIFPAppointment();
            appointment1112.PlanID = 1112;
            appointment1112.ActivityCode = "PIG-IP";
            appointment1112.Subject = "PIG-IP";
            appointment1112.UnitStatus = "CZ";
            appointment1112.Division = "CPLD";
            appointment1112.UnitName = "PL-UT137";
            appointment1112.UnitID = 42;
            appointment1112.UnitType = FIFPConstants.UNITTYPE_PIPELINE;
            appointment1112.ActivityType = "InstallDevice";
            appointment1112.FluidType = FIFPConstants.FLUIDTYPE_GAS;
            appointment1112.OriginalStart = appointment1112.Start = DateTime.Now.AddDays(18);
            appointment1112.OriginalEnd = appointment1112.End = DateTime.Now.AddDays(25);


            lstAppointments.Add(appointment11);
            lstAppointments.Add(appointment1112);

            FIFPAppointment appointment12 = new FIFPAppointment();
            appointment12.PlanID = 12;
            appointment12.ActivityCode = "MTN-PM";
            appointment12.Subject = "MTN-PM";
            appointment12.UnitStatus = "CD";
            appointment12.Division = "USAU";
            appointment12.UnitName = "UT-32";
            appointment12.UnitID = 5;
            appointment12.UnitType = "Tower";
            appointment12.ActivityType = "InstallDevice";
            appointment12.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment12.OriginalStart = appointment12.Start = DateTime.Now;
            appointment12.OriginalEnd = appointment12.End = DateTime.Now.AddMonths(1);

            FIFPAppointment appointment121 = new FIFPAppointment();
            appointment121.PlanID = 121;
            appointment121.ActivityCode = "MTN-PM";
            appointment121.Subject = "MTN-PM";
            appointment121.UnitStatus = "CD";
            appointment121.Division = "USAU";
            appointment121.UnitName = "UT-32";
            appointment121.UnitID = 5;
            appointment121.UnitType = "Tower";
            appointment121.ActivityType = "InstallDevice";
            appointment121.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment121.OriginalStart = appointment121.Start = DateTime.Now.AddDays(10);
            appointment121.OriginalEnd = appointment121.End = DateTime.Now.AddDays(20);

            FIFPAppointment appointment122 = new FIFPAppointment();
            appointment122.PlanID = 122;
            appointment122.ActivityCode = "MTN-PM";
            appointment122.Subject = "MTN-PM";
            appointment122.UnitStatus = "CD";
            appointment122.Division = "USAU";
            appointment122.UnitName = "UT-32";
            appointment122.UnitID = 5;
            appointment122.UnitType = "Tower";
            appointment122.ActivityType = "InstallDevice";
            appointment122.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment122.OriginalStart = appointment122.Start = DateTime.Now.AddDays(15);
            appointment122.OriginalEnd = appointment122.End = DateTime.Now.AddDays(30);

            lstAppointments.Add(appointment12);
            lstAppointments.Add(appointment121);
            lstAppointments.Add(appointment122);

            FIFPAppointment appointment13 = new FIFPAppointment();
            appointment13.PlanID = 13;
            appointment13.ActivityCode = "INSP-F";
            appointment13.Subject = "INSP-F";
            appointment13.UnitStatus = "CU";
            appointment13.Division = "FDD (US)";
            appointment13.UnitName = "Seperator_1";
            appointment13.UnitID = 35;
            appointment13.UnitType = "Seperator";
            appointment13.ActivityType = "InstallDevice";
            appointment13.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment13.OriginalStart = appointment13.Start = DateTime.Now.AddDays(20);
            appointment13.OriginalEnd = appointment13.End = DateTime.Now.AddDays(25);

            FIFPAppointment appointment131 = new FIFPAppointment();
            appointment131.PlanID = 131;
            appointment131.ActivityCode = "INSP-F";
            appointment131.Subject = "INSP-F";
            appointment131.UnitStatus = "CU";
            appointment131.Division = "FDD (US)";
            appointment131.UnitName = "Seperator_1";
            appointment131.UnitID = 35;
            appointment131.UnitType = "Seperator";
            appointment131.ActivityType = "InstallDevice";
            appointment131.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment131.OriginalStart = appointment131.Start = DateTime.Now.AddDays(23);
            appointment131.OriginalEnd = appointment131.End = DateTime.Now.AddDays(35);

            
            lstAppointments.Add(appointment13);
            lstAppointments.Add(appointment131);

            FIFPAppointment appointment14 = new FIFPAppointment();
            appointment14.PlanID = 14;
            appointment14.ActivityCode = "INSP-F";
            appointment14.Subject = "INSP-F";
            appointment14.UnitStatus = "CU";
            appointment14.Division = "FDD (US)";
            appointment14.UnitName = "Seperator_2";
            appointment14.UnitID = 36;
            appointment14.UnitType = "Seperator";
            appointment14.ActivityType = "InstallDevice";
            appointment14.FluidType = FIFPConstants.FLUIDTYPE_GAS;
            appointment14.OriginalStart = appointment14.Start = DateTime.Now.AddDays(15);
            appointment14.OriginalEnd = appointment14.End = DateTime.Now.AddDays(20);

            FIFPAppointment appointment141 = new FIFPAppointment();
            appointment141.PlanID = 141;
            appointment141.ActivityCode = "INSP-F";
            appointment141.Subject = "INSP-F";
            appointment141.UnitStatus = "CU";
            appointment141.Division = "FDD (US)";
            appointment141.UnitName = "Seperator_2";
            appointment141.UnitID = 36;
            appointment141.UnitType = "Seperator";
            appointment141.ActivityType = "InstallDevice";
            appointment141.FluidType = FIFPConstants.FLUIDTYPE_GAS;
            appointment141.OriginalStart = appointment141.Start = DateTime.Now.AddDays(18);
            appointment141.OriginalEnd = appointment141.End = DateTime.Now.AddDays(30);

            lstAppointments.Add(appointment14);
            lstAppointments.Add(appointment141);


            FIFPAppointment appointment15 = new FIFPAppointment();
            appointment15.PlanID = 15;
            appointment15.ActivityCode = "INSP-F";
            appointment15.Subject = "INSP-F";
            appointment15.UnitStatus = "CU";
            appointment15.Division = "CPLD";
            appointment15.UnitName = "Compressor_1";
            appointment15.UnitID = 37;
            appointment15.UnitType = "Compressor";
            appointment15.ActivityType = "InstallDevice";
            appointment15.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment15.OriginalStart = appointment15.Start = DateTime.Now.AddDays(20);
            appointment15.OriginalEnd = appointment15.End = DateTime.Now.AddDays(30);

            FIFPAppointment appointment151 = new FIFPAppointment();
            appointment151.PlanID = 151;
            appointment151.ActivityCode = "INSP-F";
            appointment151.Subject = "INSP-F";
            appointment151.UnitStatus = "CU";
            appointment151.Division = "CPLD";
            appointment151.UnitName = "Compressor_1";
            appointment151.UnitID = 37;
            appointment151.UnitType = "Compressor";
            appointment151.ActivityType = "InstallDevice";
            appointment151.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment151.OriginalStart = appointment151.Start = DateTime.Now.AddDays(25);
            appointment151.OriginalEnd = appointment151.End = DateTime.Now.AddDays(35);

            
            lstAppointments.Add(appointment15);
            lstAppointments.Add(appointment151);

            FIFPAppointment appointment16 = new FIFPAppointment();
            appointment16.PlanID = 16;
            appointment16.ActivityCode = "RGL";
            appointment16.Subject = "RGL";
            appointment16.UnitStatus = "CZ";
            appointment16.Division = "Brown Fields";
            appointment16.UnitName = "US-4";
            appointment16.UnitID = 51;
            appointment16.UnitType = "Well";
            appointment16.ActivityType = "InstallDevice";
            appointment16.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment16.OriginalStart = appointment16.Start = DateTime.Now.AddDays(10);
            appointment16.OriginalEnd = appointment16.End = DateTime.Now.AddDays(15);

            FIFPAppointment appointment161 = new FIFPAppointment();
            appointment161.PlanID = 161;
            appointment161.ActivityCode = "RGL";
            appointment161.Subject = "RGL";
            appointment161.UnitStatus = "CZ";
            appointment161.Division = "Brown Fields";
            appointment161.UnitName = "US-4";
            appointment161.UnitID = 51;
            appointment161.UnitType = "Well";
            appointment161.ActivityType = "InstallDevice";
            appointment161.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment161.OriginalStart = appointment161.Start = DateTime.Now.AddDays(12);
            appointment161.OriginalEnd = appointment161.End = DateTime.Now.AddDays(20);

            lstAppointments.Add(appointment16);
            lstAppointments.Add(appointment161);

            FIFPAppointment appointment17 = new FIFPAppointment();
            appointment17.PlanID = 17;
            appointment17.ActivityCode = "MTN-SS";
            appointment17.Subject = "MTN-SS";
            appointment17.UnitStatus = "CM";
            appointment17.Division = "CPLD";
            appointment17.UnitName = "Pipeline-3";
            appointment17.UnitID = 6;
            appointment17.UnitType = "Pipeline";
            appointment17.ActivityType = "InstallDevice";
            appointment17.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment17.OriginalStart = appointment17.Start = DateTime.Now.AddDays(-15);
            appointment17.OriginalEnd = appointment17.End = DateTime.Now.AddDays(10);

            lstAppointments.Add(appointment17);

            FIFPAppointment appointment18 = new FIFPAppointment();
            appointment18.PlanID = 18;
            appointment18.ActivityCode = "RGL";
            appointment18.Subject = "RGL";
            appointment18.UnitStatus = "CD";
            appointment18.Division = "Major Projects";
            appointment18.UnitName = "UT-137A";
            appointment18.UnitID = 9;
            appointment18.UnitType = "Tower";
            appointment18.ActivityType = "InstallDevice";
            appointment18.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment18.OriginalStart = appointment18.Start = DateTime.Now.AddDays(-50);
            appointment18.OriginalEnd = appointment18.End = DateTime.Now.AddDays(20);

            FIFPAppointment appointment181 = new FIFPAppointment();
            appointment181.PlanID = 181;
            appointment181.ActivityCode = "RGL";
            appointment181.Subject = "RGL";
            appointment181.UnitStatus = "CD";
            appointment181.Division = "Major Projects";
            appointment181.UnitName = "UT-137A";
            appointment181.UnitID = 9;
            appointment181.UnitType = "Tower";
            appointment181.ActivityType = "InstallDevice";
            appointment181.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment181.OriginalStart = appointment181.Start = DateTime.Now.AddDays(10);
            appointment181.OriginalEnd = appointment181.End = DateTime.Now.AddDays(20);

            FIFPAppointment appointment182 = new FIFPAppointment();
            appointment182.PlanID = 182;
            appointment182.ActivityCode = "RGL";
            appointment182.Subject = "RGL";
            appointment182.UnitStatus = "CD";
            appointment182.Division = "Major Projects";
            appointment182.UnitName = "UT-137A";
            appointment182.UnitID = 9;
            appointment182.UnitType = "Tower";
            appointment182.ActivityType = "InstallDevice";
            appointment182.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment182.OriginalStart = appointment182.Start = DateTime.Now.AddDays(15);
            appointment182.OriginalEnd = appointment182.End = DateTime.Now.AddDays(40);


            lstAppointments.Add(appointment18);
            lstAppointments.Add(appointment181);
            lstAppointments.Add(appointment182);

            FIFPAppointment appointment19 = new FIFPAppointment();
            appointment19.PlanID = 19;
            appointment19.ActivityCode = "RGL";
            appointment19.Subject = "RGL";
            appointment19.UnitStatus = "CD";
            appointment19.Division = "OGCD";
            appointment19.UnitName = "US-148";
            appointment19.UnitID = 91;
            appointment19.UnitType = "Well";
            appointment19.ActivityType = "InstallDevice";
            appointment19.FluidType = FIFPConstants.FLUIDTYPE_GAS;
            appointment19.OriginalStart = appointment19.Start = DateTime.Now.AddDays(-75);
            appointment19.OriginalEnd = appointment19.End = DateTime.Now.AddDays(10);

            lstAppointments.Add(appointment19);


            FIFPAppointment appointment20 = new FIFPAppointment();
            appointment20.PlanID = 20;
            appointment20.ActivityCode = "PRO-B";
            appointment20.Subject = "PRO-B";
            appointment20.UnitStatus = "CE";
            appointment20.Division = "FDD (US)";
            appointment20.UnitName = "Module_1";
            appointment20.UnitID = 92;
            appointment20.UnitType = "Module";
            appointment20.ActivityType = "InstallDevice";
            appointment20.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment20.OriginalStart = appointment20.Start = DateTime.Now.AddDays(-65);
            appointment20.OriginalEnd = appointment20.End = DateTime.Now.AddDays(25);

            FIFPAppointment appointment201 = new FIFPAppointment();
            appointment201.PlanID = 201;
            appointment201.ActivityCode = "PRO-B";
            appointment201.Subject = "PRO-B";
            appointment201.UnitStatus = "CE";
            appointment201.Division = "FDD (US)";
            appointment201.UnitName = "Module_1";
            appointment201.UnitID = 92;
            appointment201.UnitType = "Module";
            appointment201.ActivityType = "InstallDevice";
            appointment201.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment201.OriginalStart = appointment201.Start = DateTime.Now.AddDays(15);
            appointment201.OriginalEnd = appointment201.End = DateTime.Now.AddDays(22);

            FIFPAppointment appointment202 = new FIFPAppointment();
            appointment202.PlanID = 202;
            appointment202.ActivityCode = "PRO-B";
            appointment202.Subject = "PRO-B";
            appointment202.UnitStatus = "CE";
            appointment202.Division = "FDD (US)";
            appointment202.UnitName = "Module_1";
            appointment202.UnitID = 92;
            appointment202.UnitType = "Module";
            appointment202.ActivityType = "InstallDevice";
            appointment202.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment202.OriginalStart = appointment202.Start = DateTime.Now.AddDays(20);
            appointment202.OriginalEnd = appointment202.End = DateTime.Now.AddDays(35);

            FIFPAppointment appointment203 = new FIFPAppointment();
            appointment203.PlanID = 203;
            appointment203.ActivityCode = "PRO-B";
            appointment203.Subject = "PRO-B";
            appointment203.UnitStatus = "CE";
            appointment203.Division = "FDD (US)";
            appointment203.UnitName = "Module_1";
            appointment203.UnitID = 92;
            appointment203.UnitType = "Module";
            appointment203.ActivityType = "InstallDevice";
            appointment203.FluidType = FIFPConstants.FLUIDTYPE_WATER;
            appointment203.OriginalStart = appointment203.Start = DateTime.Now.AddDays(65);
            appointment203.OriginalEnd = appointment203.End = DateTime.Now.AddDays(75);

            lstAppointments.Add(appointment20);
            lstAppointments.Add(appointment201);
            lstAppointments.Add(appointment202);
            lstAppointments.Add(appointment203);



            FIFPAppointment appointment22 = new FIFPAppointment();
            appointment22.PlanID = 22;
            appointment22.ActivityCode = "ENG";
            appointment22.Subject = "ENG";
            appointment22.UnitStatus = "CD";
            appointment22.Division = "Maintenance";
            appointment22.UnitName = "Spheroid_1";
            appointment22.UnitID = 2222;
            appointment22.UnitType = "Spheroid";
            appointment22.ActivityType = "Maintenance";
            appointment22.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment22.OriginalStart = appointment22.Start = DateTime.Now.AddDays(45);
            appointment22.OriginalEnd = appointment22.End = DateTime.Now.AddDays(60);

            FIFPAppointment appointment23 = new FIFPAppointment();
            appointment23.PlanID = 23;
            appointment23.ActivityCode = "ENG";
            appointment23.Subject = "ENG";
            appointment23.UnitStatus = "CD";
            appointment23.Division = "Maintenance";
            appointment23.UnitName = "Spheroid_1";
            appointment23.UnitID = 2222;
            appointment23.UnitType = "Spheroid";
            appointment23.ActivityType = "Maintenance";
            appointment23.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment23.OriginalStart = appointment23.Start = DateTime.Now.AddDays(50);
            appointment23.OriginalEnd = appointment23.End = DateTime.Now.AddDays(70);

            FIFPAppointment appointment231 = new FIFPAppointment();
            appointment231.PlanID = 231;
            appointment231.ActivityCode = "ENG";
            appointment231.Subject = "ENG";
            appointment231.UnitStatus = "CD";
            appointment231.Division = "Maintenance";
            appointment231.UnitName = "Spheroid_1";
            appointment231.UnitID = 2222;
            appointment231.UnitType = "Spheroid";
            appointment231.ActivityType = "Maintenance";
            appointment231.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment231.OriginalStart = appointment231.Start = DateTime.Now.AddDays(80);
            appointment231.OriginalEnd = appointment231.End = DateTime.Now.AddDays(90);

            lstAppointments.Add(appointment22);
            lstAppointments.Add(appointment23);
            lstAppointments.Add(appointment231);

            FIFPAppointment appointment24 = new FIFPAppointment();
            appointment24.PlanID = 24;
            appointment24.ActivityCode = "LOG";
            appointment24.Subject = "LOG";
            appointment24.UnitStatus = "CD";
            appointment24.Division = "Maintenance";
            appointment24.UnitName = "Stripper_1";
            appointment24.UnitID = 2223;
            appointment24.UnitType = "Stripper";
            appointment24.ActivityType = "Maintenance";
            appointment24.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment24.OriginalStart = appointment24.Start = DateTime.Now.AddDays(15);
            appointment24.OriginalEnd = appointment24.End = DateTime.Now.AddDays(20);

            FIFPAppointment appointment241 = new FIFPAppointment();
            appointment241.PlanID = 241;
            appointment241.ActivityCode = "LOG";
            appointment241.Subject = "LOG";
            appointment241.UnitStatus = "CD";
            appointment241.Division = "Maintenance";
            appointment241.UnitName = "Stripper_1";
            appointment241.UnitID = 2223;
            appointment241.UnitType = "Stripper";
            appointment241.ActivityType = "Maintenance";
            appointment241.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment241.OriginalStart = appointment241.Start = DateTime.Now.AddDays(19);
            appointment241.OriginalEnd = appointment241.End = DateTime.Now.AddDays(30);

            FIFPAppointment appointment242 = new FIFPAppointment();
            appointment242.PlanID = 242;
            appointment242.ActivityCode = "LOG";
            appointment242.Subject = "LOG";
            appointment242.UnitStatus = "CD";
            appointment242.Division = "Maintenance";
            appointment242.UnitName = "Stripper_1";
            appointment242.UnitID = 2223;
            appointment242.UnitType = "Stripper";
            appointment242.ActivityType = "Maintenance";
            appointment242.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment242.OriginalStart = appointment242.Start = DateTime.Now.AddDays(22);
            appointment242.OriginalEnd = appointment242.End = DateTime.Now.AddDays(30);

            
            lstAppointments.Add(appointment24);
            lstAppointments.Add(appointment241);
            lstAppointments.Add(appointment242);

            FIFPAppointment appointment25 = new FIFPAppointment();
            appointment25.PlanID = 25;
            appointment25.ActivityCode = "PNT";
            appointment25.Subject = "PNT";
            appointment25.UnitStatus = "CD";
            appointment25.Division = "Maintenance";
            appointment25.UnitName = "Tower-5";
            appointment25.UnitID = 10;
            appointment25.UnitType = "Tower";
            appointment25.ActivityType = "Maintenance";
            appointment25.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment25.OriginalStart = appointment25.Start = DateTime.Now.AddDays(10);
            appointment25.OriginalEnd = appointment25.End = DateTime.Now.AddDays(15);

            FIFPAppointment appointment251 = new FIFPAppointment();
            appointment251.PlanID = 251;
            appointment251.ActivityCode = "PNT";
            appointment251.Subject = "PNT";
            appointment251.UnitStatus = "CD";
            appointment251.Division = "Maintenance";
            appointment251.UnitName = "Tower-5";
            appointment251.UnitID = 10;
            appointment251.UnitType = "Tower";
            appointment251.ActivityType = "Maintenance";
            appointment251.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment251.OriginalStart = appointment251.Start = DateTime.Now.AddDays(40);
            appointment251.OriginalEnd = appointment251.End = DateTime.Now.AddDays(50);

            FIFPAppointment appointment252 = new FIFPAppointment();
            appointment252.PlanID = 252;
            appointment252.ActivityCode = "PNT";
            appointment252.Subject = "PNT";
            appointment252.UnitStatus = "CD";
            appointment252.Division = "Maintenance";
            appointment252.UnitName = "Tower-5";
            appointment252.UnitID = 10;
            appointment252.UnitType = "Tower";
            appointment252.ActivityType = "Maintenance";
            appointment252.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment252.OriginalStart = appointment252.Start = DateTime.Now.AddDays(25);
            appointment252.OriginalEnd = appointment252.End = DateTime.Now.AddDays(33);


            lstAppointments.Add(appointment25);
            lstAppointments.Add(appointment251);
            lstAppointments.Add(appointment252);

            FIFPAppointment appointment26 = new FIFPAppointment();
            appointment26.PlanID = 26;
            appointment26.ActivityCode = "RIG";
            appointment26.Subject = "RIG";
            appointment26.UnitStatus = "CD";
            appointment26.Division = "Maintenance";
            appointment26.UnitName = "Well-8";
            appointment26.UnitID = 101;
            appointment26.UnitType = "Well";
            appointment26.ActivityType = "Maintenance";
            appointment26.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment26.OriginalStart = appointment26.Start = DateTime.Now.AddDays(13);
            appointment26.OriginalEnd = appointment26.End = DateTime.Now.AddDays(25);

            FIFPAppointment appointment261 = new FIFPAppointment();
            appointment261.PlanID = 261;
            appointment261.ActivityCode = "RIG";
            appointment261.Subject = "RIG";
            appointment261.UnitStatus = "CD";
            appointment261.Division = "Maintenance";
            appointment261.UnitName = "Well-8";
            appointment261.UnitID = 101;
            appointment261.UnitType = "Well";
            appointment261.ActivityType = "Maintenance";
            appointment261.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment261.OriginalStart = appointment261.Start = DateTime.Now.AddDays(45);
            appointment261.OriginalEnd = appointment261.End = DateTime.Now.AddDays(55);

            FIFPAppointment appointment262 = new FIFPAppointment();
            appointment262.PlanID = 262;
            appointment262.ActivityCode = "RIG";
            appointment262.Subject = "RIG";
            appointment262.UnitStatus = "CD";
            appointment262.Division = "Maintenance";
            appointment262.UnitName = "Well-8";
            appointment262.UnitID = 101;
            appointment262.UnitType = "Well";
            appointment262.ActivityType = "Maintenance";
            appointment262.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment262.OriginalStart = appointment262.Start = DateTime.Now.AddDays(26);
            appointment262.OriginalEnd = appointment262.End = DateTime.Now.AddDays(30);

            FIFPAppointment appointment263 = new FIFPAppointment();
            appointment263.PlanID = 263;
            appointment263.ActivityCode = "RIG";
            appointment263.Subject = "RIG";
            appointment263.UnitStatus = "CD";
            appointment263.Division = "Maintenance";
            appointment263.UnitName = "String-6";
            appointment263.UnitID = 102;
            appointment263.UnitType = "String";
            appointment263.ActivityType = "Maintenance";
            appointment263.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment263.OriginalStart = appointment263.Start = DateTime.Now.AddDays(35);
            appointment263.OriginalEnd = appointment263.End = DateTime.Now.AddDays(40);

            FIFPAppointment appointment264 = new FIFPAppointment();
            appointment264.PlanID = 264;
            appointment264.ActivityCode = "RIG";
            appointment264.Subject = "RIG";
            appointment264.UnitStatus = "CD";
            appointment264.Division = "Maintenance";
            appointment264.UnitName = "String-6";
            appointment264.UnitID = 102;
            appointment264.UnitType = "String";
            appointment264.ActivityType = "Maintenance";
            appointment264.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment264.OriginalStart = appointment264.Start = DateTime.Now.AddDays(35);
            appointment264.OriginalEnd = appointment264.End = DateTime.Now.AddDays(40);


            lstAppointments.Add(appointment26);
            lstAppointments.Add(appointment261);
            lstAppointments.Add(appointment262);

            lstAppointments.Add(appointment263);
            lstAppointments.Add(appointment264);


            FIFPAppointment appointment27 = new FIFPAppointment();
            appointment27.PlanID = 27;
            appointment27.ActivityCode = "MTN-SS";
            appointment27.Subject = "MTN-SS";
            appointment27.UnitStatus = "CD";
            appointment27.Division = "Maintenance";
            appointment27.UnitName = "Pipeline-7";
            appointment27.UnitID = 103;
            appointment27.UnitType = "Pipeline";
            appointment27.ActivityType = "Maintenance";
            appointment27.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment27.OriginalStart = appointment27.Start = DateTime.Now.AddDays(20);
            appointment27.OriginalEnd = appointment27.End = DateTime.Now.AddDays(35);

            FIFPAppointment appointment271 = new FIFPAppointment();
            appointment271.PlanID = 271;
            appointment271.ActivityCode = "MTN-SS";
            appointment271.Subject = "MTN-SS";
            appointment271.UnitStatus = "CD";
            appointment271.Division = "Maintenance";
            appointment271.UnitName = "Pipeline-7";
            appointment271.UnitID = 103;
            appointment271.UnitType = "Pipeline";
            appointment271.ActivityType = "Maintenance";
            appointment271.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment271.OriginalStart = appointment271.Start = DateTime.Now.AddDays(57);
            appointment271.OriginalEnd = appointment271.End = DateTime.Now.AddDays(65);

            FIFPAppointment appointment272 = new FIFPAppointment();
            appointment272.PlanID = 272;
            appointment272.ActivityCode = "MTN-SS";
            appointment272.Subject = "MTN-SS";
            appointment272.UnitStatus = "CD";
            appointment272.Division = "Maintenance";
            appointment272.UnitName = "Pipeline-7";
            appointment272.UnitID = 103;
            appointment272.UnitType = "Pipeline";
            appointment272.ActivityType = "Maintenance";
            appointment272.FluidType = FIFPConstants.FLUIDTYPE_OIL;
            appointment272.OriginalStart = appointment272.Start = DateTime.Now.AddDays(64);
            appointment272.OriginalEnd = appointment272.End = DateTime.Now.AddDays(75);

            lstAppointments.Add(appointment27);
            lstAppointments.Add(appointment271);
            lstAppointments.Add(appointment272);

            if (lstAppointments != null && lstAppointments.Count > 0)
            {
                foreach (FIFPAppointment appointment in lstAppointments)
                {
                    if (!string.IsNullOrEmpty(appointment.FluidType))
                    {
                        switch (appointment.FluidType)
                        {
                            case FIFPConstants.FLUIDTYPE_OIL:
                            case FIFPConstants.FLUIDTYPE_COMBINED:
                                appointment.Category = new Category("Oil", new SolidColorBrush(new Color() { R = 0xFF, G = 0x59, B = 0x59, A = 0xFF }));
                                break;
                            case FIFPConstants.FLUIDTYPE_WATER:
                                appointment.Category = new Category("Water", new SolidColorBrush(new Color() { R = 0x4B, G = 0xAC, B = 0xC6, A = 0xFF }));
                                break;
                            case FIFPConstants.FLUIDTYPE_GAS:
                                appointment.Category = new Category("Gas", new SolidColorBrush(new Color() { R = 0x93, G = 0xA8, B = 0x2A, A = 0xFF }));
                                break;
                            default:
                                break;
                        }
                    }
                }
            }

            foreach (FIFPAppointment appointment in lstAppointments)
            {
                appointment.nIndex = (appointment.UnitType == FIFPConstants.UNITTYPE_RADIAL) ? 1 : (appointment.UnitType == FIFPConstants.UNITTYPE_TOWER) ? 2 : (appointment.UnitType == FIFPConstants.UNITTYPE_COMPRESSOR) ? 3 : (appointment.UnitType == FIFPConstants.UNITTYPE_SEPERATOR) ? 4 : (appointment.UnitType == FIFPConstants.UNITTYPE_MODULE) ? 5 : (appointment.UnitType == FIFPConstants.UNITTYPE_SPHEROID) ? 6 : (appointment.UnitType == FIFPConstants.UNITTYPE_STRIPPER) ? 7 : 0;
                if (appointment.FluidType == FIFPConstants.FLUIDTYPE_COMBINED)//Set default is OW
                    appointment.CombinedTowerLSDType = FIFPConstants.FLUIDTYPE_COMBINED;

            }

            ImportPlans = lstAppointments;

            GenerateLinkedShutdownPlans();

            DivisionList.AddRange((from item in lstAppointments
                                   select item.Division).Distinct().ToList<string>());

            SelectedDivision = DivisionList[0];


            if (SelectedScenarioId > 0)// This is no need. We have to remove it in Future 
            {
                Scenario scenario = ScenarioList.Where(s => s.ScenarioId == SelectedScenarioId).FirstOrDefault();
                if (scenario != null)
                    ImportPlans.ForEach(f => { f.ScenarioId = SelectedScenarioId; f.ScenarioName = scenario.ScenarioName; f.ScenarioDescription = scenario.ScenarioDescription; });
            }

            ServiceLocator.Get<FilterVM>().IsDivisionEnabled = true;
            ServiceLocator.Get<FilterVM>().IsFilterEnabled = true;
            IsFilterButtonEnabled = true;
            IsSaveAsEnabled = true;

            LoadTimelineView(ImportPlans);

            if (DivisionList != null && DivisionList.Count > 0)
            {
                if (OnDivisionListDataCompleted != null)
                    OnDivisionListDataCompleted(this, new CustomEventArgs<List<string>>(DivisionList));
            }
        }

        #endregion

        #region LoadTimelineView
        private void LoadTimelineView(List<FIFPAppointment> plans)
        {
            AppointmentGroup appointmentGroup = new AppointmentGroup();
            List<ResourceType> lstResources = new List<ResourceType>();
            List<Resource> unitList = new List<Resource>();
            ResourceType unitType = new ResourceType("Unit");
            unitType.DisplayName = "Unit";
            unitType.Name = "Unit";

            foreach (FIFPAppointment appointment in plans)
            {
                Resource resource = new Resource() { ResourceName = appointment.UnitName, DisplayName = appointment.UnitName, ResourceType = unitType.Name };
                //unitList.Add(resource);
                if (!unitList.Contains(resource))
                {
                    unitList.Add(resource);
                }
                appointment.Resources.Add(resource);
            }

            appointmentGroup.Appointments = new List<FIFPAppointment>(plans);
            unitType.Resources.AddRange(unitList);
            lstResources.Add(unitType);


            appointmentGroup.ResourceTypes = lstResources;
            appointmentGroup.UnitList = unitList;

            if (OnAppointmentDataCompleted != null)
                OnAppointmentDataCompleted(this, new CustomEventArgs<AppointmentGroup>(appointmentGroup));

        }
        #endregion

        #region Generate Linked Shutdown Plans
        private void GenerateLinkedShutdownPlans()
        {
            if (ImportPlans != null && ImportPlans.Count > 0)
            {
                foreach (FIFPAppointment appointment in ImportPlans)
                {
                    GetLSDPlans(UnitList.Where(p => p.UnitID == appointment.UnitID).ToList(), appointment, true);
                    /*if (appointment.UnitType == FIFPConstants.UNITTYPE_RADIAL || appointment.UnitType == FIFPConstants.SHUTDOWN_COMBINED_TOWER || appointment.UnitType == FIFPConstants.UNITTYPE_TOWER || (appointment.UnitType == FIFPConstants.UNITTYPE_WELL && appointment.ActivityCode == FIFPConstants.ACTIVITY_TYPE_RIG))
                    {
                        appointment.LsdPlans = new ObservableCollection<FIFPAppointment>(LinkedShutdownList.Where(l => l.UnitType == FIFPConstants.UNITTYPE_TOWER));
                    }
                    else
                    {
                        appointment.LsdPlans = new ObservableCollection<FIFPAppointment>(LinkedShutdownList);
                    }*/
                    appointment.LsdPlans = LinkedShutdownList;
                    LinkedShutdownList = new List<FIFPAppointment>();
                }
            }
        }
        /*
        private void GetLSDPlans(List<Unit> lstUnits, FIFPAppointment appointment, bool bInitial)
        {
            //if (bInitial)
            //{
            //    bInitial = false;
            //    if (appointment.UnitType == FIFPConstants.UNITTYPE_PIPELINE || (appointment.UnitType == FIFPConstants.UNITTYPE_WELL && appointment.ActivityCode == FIFPConstants.ACTIVITY_TYPE_RIG))
            //    {
            //        Unit defaultSDUnit = UnitList.Where(p => p.UnitID == lstUnits[0].ParentUnitID).FirstOrDefault();
            //        if (defaultSDUnit != null)
            //        {
            //            this.GetLSDPlans(UnitList.Where(p => p.ParentUnitID == defaultSDUnit.UnitID).ToList(), appointment, bInitial);
            //            //LinkedShutdownList.Add(new FIFPAppointment() { Division = appointment.Division, UnitStatus = appointment.UnitStatus, UnitID = defaultSDUnit.UnitID, UnitName = defaultSDUnit.UnitName, UnitType = defaultSDUnit.UnitType, Start = appointment.Start, End = appointment.End, FluidType = appointment.FluidType, IsAppointmentDelete = true, IsShutdownPlan = true });
            //        }
            //    }
            //}
            //else
            //{
            //    if (lstUnits != null && lstUnits.Count > 0)
            //    {
            //        foreach (Unit unit in lstUnits)
            //        {
            //            FIFPAppointment plan = ImportPlans.Where(s => s.UnitID == unit.UnitID && s.UnitName == unit.UnitName).FirstOrDefault();
            //            if (plan != null)
            //                LinkedShutdownList.Add(new FIFPAppointment() { ActivityCode = plan.ActivityCode, Division = plan.Division, UnitStatus = plan.UnitStatus, UnitID = unit.UnitID, UnitName = unit.UnitName, UnitType = unit.UnitType, Start = plan.Start, End = plan.End, OriginalStart = plan.OriginalStart, OriginalEnd = plan.OriginalEnd, FluidType = unit.FluidType, IsAppointmentDelete = true, IsShutdownPlan = true, });
             
            //            //LinkedShutdownList.Add(new FIFPAppointment() { Division = appointment.Division, UnitStatus = appointment.UnitStatus, UnitID = unit.UnitID, UnitName = unit.UnitName, UnitType = unit.UnitType, Start = appointment.Start, End = appointment.End, OriginalStart = appointment.OriginalStart, OriginalEnd = appointment.OriginalEnd, FluidType = unit.FluidType, IsAppointmentDelete = true, IsShutdownPlan = true, });
            //        }
            //    }
            //}

            foreach (Unit unit1 in lstUnits)
            {
                List<Unit> ChildUnitList = UnitList.Where(p => p.ParentUnitID == unit1.UnitID).ToList<Unit>();
                foreach (Unit unit in ChildUnitList)
                {
                    FIFPAppointment plan = ImportPlans.Where(s => s.UnitID == unit.UnitID && s.UnitName == unit.UnitName).FirstOrDefault();
                    if (plan != null)
                        LinkedShutdownList.Add(new FIFPAppointment() { ActivityCode = plan.ActivityCode, Division = plan.Division, UnitStatus = plan.UnitStatus, UnitID = unit.UnitID, UnitName = unit.UnitName, UnitType = unit.UnitType, Start = plan.Start, End = plan.End, OriginalStart = plan.OriginalStart, OriginalEnd = plan.OriginalEnd, FluidType = unit.FluidType, IsAppointmentDelete = true, IsShutdownPlan = true, });
                }
                this.GetLSDPlans(UnitList.Where(p => p.ParentUnitID == unit1.UnitID).ToList<Unit>(), appointment, bInitial);
            }
        }
        */
        private void GetLSDPlans(List<Unit> lstUnits, FIFPAppointment appointment, bool bInitial)
        {
            if (bInitial)
            {
                bInitial = false;
                if (appointment.UnitType == FIFPConstants.UNITTYPE_WELL && appointment.ActivityCode == FIFPConstants.ACTIVITY_TYPE_RIG)
                {
                    if (lstUnits != null && lstUnits.Count > 0)
                    {
                        Unit defaultSDUnit = UnitList.Where(p => p.UnitID == lstUnits[0].ParentUnitID).FirstOrDefault();
                        if (defaultSDUnit != null)
                        {
                            this.GetLSDPlans(UnitList.Where(p => p.ParentUnitID == defaultSDUnit.UnitID).ToList(), appointment, bInitial);
                            //LinkedShutdownList.Add(new FIFPAppointment() { Division = appointment.Division, UnitStatus = appointment.UnitStatus, UnitID = defaultSDUnit.UnitID, UnitName = defaultSDUnit.UnitName, UnitType = defaultSDUnit.UnitType, Start = appointment.Start, End = appointment.End, FluidType = appointment.FluidType, IsAppointmentDelete = true, IsShutdownPlan = true });
                        }
                    }
                }
            }
            else
            {
                if (lstUnits != null && lstUnits.Count > 0)
                {
                    foreach (Unit unit in lstUnits)
                    {
                        FIFPAppointment plan = ImportPlans.Where(s => s.UnitID == unit.UnitID && s.UnitName == unit.UnitName).FirstOrDefault();
                        if (plan != null)
                            LinkedShutdownList.Add(new FIFPAppointment() { ActivityCode = plan.ActivityCode, Division = plan.Division, UnitStatus = plan.UnitStatus, UnitID = unit.UnitID, UnitName = unit.UnitName, UnitType = unit.UnitType, Start = plan.Start, End = plan.End, OriginalStart = plan.OriginalStart, OriginalEnd = plan.OriginalEnd, FluidType = unit.FluidType, IsAppointmentDelete = true, IsLinkedShutdownPlan = true, });

                        //LinkedShutdownList.Add(new FIFPAppointment() { Division = appointment.Division, UnitStatus = appointment.UnitStatus, UnitID = unit.UnitID, UnitName = unit.UnitName, UnitType = unit.UnitType, Start = appointment.Start, End = appointment.End, OriginalStart = appointment.OriginalStart, OriginalEnd = appointment.OriginalEnd, FluidType = unit.FluidType, IsAppointmentDelete = true, IsShutdownPlan = true, });
                    }
                }
            }

            foreach (Unit unit in lstUnits)
            {
                this.GetLSDPlans(UnitList.Where(p => p.ParentUnitID == unit.UnitID).ToList<Unit>(), appointment, bInitial);
            }
        }

        #endregion

        #region Create Linked Shutdown Plan
        private FIFPAppointment CreateLinkedShutdownPlan()
        {
            return new FIFPAppointment();
        }
        #endregion

        #region Menu Click Events
        private void ChangeSelectedButtonStyle(Button btnSave)
        {
            string tag = string.Empty;
            if (btnSave != null && btnSave.Tag != null)
                tag = Convert.ToString(btnSave.Tag);
            switch (tag)
            {
                case FIFPConstants.HYPERLINK_OPENRAWDATA:
                    OpenRawDataStyle = Application.Current.Resources[FIFPConstants.BUTTON_SELECTEDCOLOR] as Style;
                    OpenBaseScenarioStyle = ScenarioStyle = SaveAsStyle = SaveStyle = Application.Current.Resources[FIFPConstants.BUTTON_DEFAULTCOLOR] as Style;
                    break;
                case FIFPConstants.HYPERLINK_OPENBASE_SCENARIO:
                    OpenBaseScenarioStyle = Application.Current.Resources[FIFPConstants.BUTTON_SELECTEDCOLOR] as Style;
                    OpenRawDataStyle = ScenarioStyle = SaveAsStyle = SaveStyle = Application.Current.Resources[FIFPConstants.BUTTON_DEFAULTCOLOR] as Style;
                    break;
                case FIFPConstants.HYPERLINK_OPENSCENARIO:
                    ScenarioStyle = Application.Current.Resources[FIFPConstants.BUTTON_SELECTEDCOLOR] as Style;
                    OpenRawDataStyle = OpenBaseScenarioStyle = SaveAsStyle = SaveStyle = Application.Current.Resources[FIFPConstants.BUTTON_DEFAULTCOLOR] as Style;
                    break;
                case FIFPConstants.HYPERLINK_SAVE:
                    SaveStyle = Application.Current.Resources[FIFPConstants.BUTTON_SELECTEDCOLOR] as Style;
                    OpenRawDataStyle = OpenBaseScenarioStyle = ScenarioStyle = SaveAsStyle = Application.Current.Resources[FIFPConstants.BUTTON_DEFAULTCOLOR] as Style;
                    break;
                case FIFPConstants.HYPERLINK_SAVEAS:
                    SaveAsStyle = Application.Current.Resources[FIFPConstants.BUTTON_SELECTEDCOLOR] as Style;
                    OpenRawDataStyle = OpenBaseScenarioStyle = ScenarioStyle = SaveStyle = Application.Current.Resources[FIFPConstants.BUTTON_DEFAULTCOLOR] as Style;
                    break;
            }
        }
        #endregion

        #region SaveAs Button Logic
        private void SaveAsScenario(Button btnSaveAs)
        {
            ChangeSelectedButtonStyle(btnSaveAs);
            if (ImportPlans != null && ImportPlans.Count > 0)
            {
                List<FIFPAppointment> lstAppointments = (from item in ImportPlans
                                                         where item.ScenarioId == 0
                                                         select item).ToList<FIFPAppointment>();
                if (lstAppointments != null && lstAppointments.Count > 0 && isOpenRawData)
                {
                    ShowPopup(FIFPConstants.WARNINGTITLE_BASE_ALREADY, FIFPConstants.WARNINGMESSAGE_BASE_ALREADY);
                }
                else if (!IsBaseScenario)
                {
                    IsBaseScenario = true;
                    isOpenBaseScenario = false;// Once we save it base scenario, then if the user click save as once again without go to open base scenario then we can show already base scenario exists messge
                    isOpenRawData = true;//
                    ShowPopup(FIFPConstants.WARNINGTITLE_SAVEAS_BASICSCENARIO, FIFPConstants.WARNINGMESSAGE_SAVEAS_BASICSCENARIO);
                    ImportPlans.ForEach(f => { f.ScenarioId = 0; f.ScenarioName = "Basic"; f.ScenarioDescription = "Basic Senario"; });
                }
                else if (isOpenBaseScenario && IsBaseScenario)
                {
                    scenarioPopup = new CreateScenarioPopup();
                    scenarioPopup.Closed += new EventHandler(scenarioPopup_Closed);
                    scenarioPopup.Show();
                }
                else
                    ShowNoBaseScenarioMessage();
            }
            else
            {
                ShowNoBaseScenarioMessage();
            }
        }

        void scenarioPopup_Closed(object sender, EventArgs e)
        {
        }


        #endregion

        #region Save Button Logic
        private void SaveScenario(Button btnSaveAs)
        {
            ChangeSelectedButtonStyle(btnSaveAs);
            ShowPopup(FIFPConstants.WARNINGTITLE_SAVE_SCENARIO, FIFPConstants.WARNINGMESSAGE_SAVE_SCENARIO);
            //TODO Save Logic
        }
        #endregion

        #region Calculate Button Logic
        private Point startPoint = new Point(20, 20);
        private void Calculate(Button btnSaveAs)
        {
            //ServiceLocator.Get<Import>().host.CloseAllWindows();
            if (reportWindow == null)
            {
                reportWindow = new Report();
                ServiceLocator.Get<Import>().host.Add(reportWindow);

            }
            reportWindow.Activated += (s, a) =>
            {
            };

            reportWindow.Deactivated += (s, a) =>
            {
            };

            reportWindow.Closed += (s, a) =>
            {
                reportWindow = null;
            };

            reportWindow.Show(startPoint);
            //TODO Save Logic
        }
        #endregion

        #region Open Basic Scenario Button Logic
        private void OpenBasicScenario(Button btnBasicScenario)
        {
            isOpenRawData = false;
            isOpenBaseScenario = true;
            ChangeSelectedButtonStyle(btnBasicScenario);
            if (ImportPlans != null && ImportPlans.Count > 0)
            {
                List<FIFPAppointment> baseScenarioList = (from item in ImportPlans
                                                          where item.ScenarioId == 0
                                                          select item).ToList<FIFPAppointment>();
                if (baseScenarioList != null && baseScenarioList.Count > 0)
                {
                    IsBaseScenarioEnabled = false;
                    ServiceLocator.Get<MainPageVM>().IsIntegrationEnabled = true;
                    IsSaveAsEnabled = true;
                    if (App.LoginUserId == FIFPConstants.ADMIN_USERS)
                        IsSaveEnabled = true;
                    else
                        IsSaveEnabled = false;
                    BindScenarioToScheduleView(baseScenarioList);
                }
                else
                {
                    IsBaseScenarioEnabled = true;
                    //isOpenRawData = true;
                    //isOpenBaseScenario = false;
                    ShowNoBaseScenarioMessage();
                }
            }
            else
                ShowNoBaseScenarioMessage();
        }

        private void BindScenarioToScheduleView(List<FIFPAppointment> baseScenarioList)
        {
            AppointmentGroup appointmentGroup = new AppointmentGroup();
            List<ResourceType> lstResources = new List<ResourceType>();
            List<Resource> unitList = new List<Resource>();
            ResourceType unitType = new ResourceType("Unit");
            unitType.DisplayName = "Unit";
            unitType.Name = "Unit";
            foreach (FIFPAppointment appointment in baseScenarioList)
            {
                Resource resource = new Resource() { ResourceName = appointment.UnitName, DisplayName = appointment.UnitName, ResourceType = unitType.Name };
                if (!unitList.Contains(resource))
                    unitList.Add(resource);
                appointment.Resources.Add(resource);
            }

            appointmentGroup.Appointments = baseScenarioList;
            unitType.Resources.AddRange(unitList);
            lstResources.Add(unitType);


            appointmentGroup.ResourceTypes = lstResources;
            appointmentGroup.UnitList = unitList;

            if (OnAppointmentDataCompleted != null)
                OnAppointmentDataCompleted(this, new CustomEventArgs<AppointmentGroup>(appointmentGroup));
        }
        #endregion

        #region Open Scenario Button Logic
        private void OpenScenario(Button btnScenario)
        {
            ChangeSelectedButtonStyle(btnScenario);

            if (ScenarioList != null && ScenarioList.Count > 0)
            {
                IsSaveAsEnabled = true;
                ServiceLocator.Get<MainPageVM>().IsIntegrationEnabled = true;
                openScenarioPopup = new OpenScenarioPopup();
                openScenarioPopup.Closed += new EventHandler(openScenarioPopup_Closed);
                openScenarioPopup.Show();
            }
            else
            {
                IsBaseScenarioEnabled = true;

                ShowPopup(FIFPConstants.WARNINGTITLE_OPENSCENARIO, FIFPConstants.WARNINGMESSAGE_OPENSCENARIO);
            }
        }

        private void ShowPopup(string title, string message)
        {
            Warning warningWindow = new Warning();
            warningWindow.CancelButton.Visibility = Visibility.Collapsed;
            warningWindow.Title = string.Format(title);
            warningWindow.lblMessage.Text = string.Format(message);
            warningWindow.lblMessage.Visibility = Visibility.Visible;
            warningWindow.Show();
            Application.Current.RootVisual.SetValue(Control.IsEnabledProperty, true);
            warningWindow.OKButton.Click += (o, e1) =>
            {
                warningWindow.lblMessage.Visibility = Visibility.Collapsed;
                Application.Current.RootVisual.SetValue(Control.IsEnabledProperty, true);
            };
        }

        void openScenarioPopup_Closed(object sender, EventArgs e)
        {
        }
        #endregion

        #region ShowNoBaseScenarioMessage
        private void ShowNoBaseScenarioMessage()
        {
            ShowPopup(FIFPConstants.WARNINGTITLE_BASE_NO, FIFPConstants.WARNINGMESSAGE_BASE_NO);
        }
        #endregion

        #region SelectedOpenScenario
        private void SelectedOpenScenario(RadioButton rdScenario)
        {
            if (rdScenario != null && rdScenario.Tag != null)
                SelectedScenarioId = Convert.ToInt32(rdScenario.Tag);
        }
        #endregion

        #region OpenCurrentUserScenario
        private void OpenCurrentUserScenario(Button btnScenario)
        {
            IsSaveEnabled = true;
            if (SelectedScenarioId > 0)
            {
                LoadScenarioPlansToScheduleView(SelectedScenarioId);// This is for Caching
                HidePopup(btnScenario);
            }
        }
        #endregion

        #region LoadScenarioPlansToScheduleView
        private void LoadScenarioPlansToScheduleView(int scenarioId)
        {
            if (ScenarioPlans != null && ScenarioPlans.Count > 0)
            {
                BindScenarioToScheduleView(ImportPlans);
                //BindScenarioToScheduleView(ImportPlans.Where(s => s.ScenarioId == scenarioId).ToList<FIFPAppointment>());
            }
        }
        #endregion

        #region HidePopup
        private void HidePopup(Button btnCancel)
        {
            _validationResults.Clear();
            ScenarioName = string.Empty;
            if (scenarioPopup != null)
                scenarioPopup.Close();
            if (openScenarioPopup != null)
                openScenarioPopup.Close();
        }
        #endregion

        #region ShowPopup
        private void ShowPopup(Button btnShow)
        {
            IsScenarioExist = false;

            List<FIFPAppointment> lstScenarioPlans = new List<FIFPAppointment>();
            if (CheckValidation())
            {
                int maxRowId = ImportPlans.Max(m => m.ScenarioId);//Temporary logic. We have to change this once we connect to database.
                lstScenarioPlans = ImportPlans;
                if (lstScenarioPlans != null && lstScenarioPlans.Count > 0)
                {
                    foreach (FIFPAppointment appointment in lstScenarioPlans)
                    {
                        appointment.ScenarioId = maxRowId + 1; appointment.ScenarioName = ScenarioName; appointment.ScenarioDescription = "Senario Description" + Convert.ToInt32(maxRowId + 1);
                    }
                    ScenarioPlans.AddRange(lstScenarioPlans);
                    ScenarioList.Add(new Scenario() { ScenarioId = maxRowId + 1, ScenarioName = ScenarioName, ScenarioDescription = "Senario Description" + Convert.ToInt32(maxRowId + 1) });
                }
                _validationResults.Clear();
                ScenarioName = string.Empty;
                scenarioPopup.Close();
            }
        }
        #endregion

        #region CheckValidation
        private bool CheckValidation()
        {
            bool bRet = true;

            if (string.IsNullOrEmpty(ScenarioName))
            {
                bRet = false;
                IsScenarioExist = false;
                NotifyPropertyChanged(() => ScenarioName);
            }
            else if (!string.IsNullOrEmpty(ScenarioName) && ScenarioList.Where(s => s.ScenarioName.Contains(ScenarioName)).FirstOrDefault() != null)
            {
                bRet = false;
                IsScenarioExist = true;
                NotifyPropertyChanged(() => ScenarioName);
            }
            return bRet;
        }
        #endregion

        #region Filter with all criteria
        private void DoFilterButtonVisibility(RadioButton rdFilter)
        {
            _validationResults.Clear();
            UnitName = string.Empty;
            IsUnitNameExist = false;

            string filterType = string.Empty;
            if (rdFilter != null && rdFilter.Tag != null)
                filterType = Convert.ToString(rdFilter.Tag);

            if (FilterTreeVisibility == Visibility.Visible)
                BindScenarioToScheduleView(ImportPlans);

            if (!string.IsNullOrEmpty(filterType))
            {
                switch (filterType)
                {
                    case "filter":
                        FilterVisibility = FilterVisibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
                        FilterTreeVisibility = Visibility.Collapsed;
                        break;
                    case "filtertree":
                        FilterVisibility = Visibility.Collapsed;
                        FilterTreeVisibility = FilterTreeVisibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
                        break;
                }

            }
        }
        #endregion

        #region Filter with unit name
        private void FilterByUnitName(Button rdFilter)
        {
            if (CheckUnitNameValidation())
            {
                if (ImportPlans != null && ImportPlans.Count > 0)
                {
                    List<FIFPAppointment> lstAppointments = (from item in ImportPlans
                                                             where item.UnitName == UnitName
                                                             select item).ToList<FIFPAppointment>();
                    BindScenarioToScheduleView(lstAppointments);
                }
                else
                    BindScenarioToScheduleView(ImportPlans);

            }
        }
        #endregion

        #region CheckUnitNameValidation
        private bool CheckUnitNameValidation()
        {
            bool bRet = true;

            if (string.IsNullOrEmpty(UnitName))
            {
                bRet = false;
                IsUnitNameExist = false;
                NotifyPropertyChanged(() => UnitName);
            }
            else if (!string.IsNullOrEmpty(UnitName) && ImportPlans.Where(s => s.UnitName.Contains(UnitName)).FirstOrDefault() == null)
            {
                bRet = false;
                IsUnitNameExist = true;
                NotifyPropertyChanged(() => UnitName);
            }
            else
            {
                bRet = true;
                IsUnitNameExist = false;
                NotifyPropertyChanged(() => UnitName);
            }
            return bRet;
        }
        #endregion

        #region Validation
        protected void NotifyPropertyChanged(Expression<Func<object>> propertyExpression)
        {
            if (propertyExpression == null)
                throw new ArgumentNullException(FIFPConstants.propertyExpression);

            var propertyName = GetPropertyName(propertyExpression);
            OnPropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            Validate(propertyName);
            OnNotifyPropertyChanged();
        }

        protected virtual void OnNotifyPropertyChanged() { }

        private string GetPropertyName(Expression<Func<object>> propertyExpression)
        {
            var unaryExpression = propertyExpression.Body as UnaryExpression;
            var memberExpression = unaryExpression == null ? (MemberExpression)propertyExpression.Body : (MemberExpression)unaryExpression.Operand;

            var propertyName = memberExpression.Member.Name;

            return propertyName;
        }


        private void NotifyErrorsChanged(string propertyName)
        {
            ErrorsChanged(this, new DataErrorsChangedEventArgs(propertyName));
        }

        protected void Validate(string propertyName)
        {
            var value = GetPropertyValue(propertyName);
            RemoveErrorsForProperty(propertyName);
            Validator.TryValidateProperty(value, new ValidationContext(this, null, null) { MemberName = propertyName }, _validationResults);
            NotifyErrorsChanged(propertyName);
        }

        protected void Validate()
        {
            _validationResults.Clear();
            Validator.TryValidateObject(this, new ValidationContext(this, null, null), _validationResults, true);

            foreach (var result in _validationResults)
                NotifyErrorsChanged(result.MemberNames.First());

        }

        private object GetPropertyValue(string propertyName)
        {
            var type = this.GetType();

            var propertyInfo = type.GetProperty(propertyName);

            if (propertyInfo == null)
            {
                throw new ArgumentException(string.Format(FIFPConstants.Couldntfindanyproperty, propertyName, type));
            }

            return propertyInfo.GetValue(this, null);
        }

        private void RemoveErrorsForProperty(string propertyName)
        {
            var validationResults = _validationResults.Where(result => result.MemberNames.Contains(propertyName)).ToList();

            foreach (var result in validationResults)
                _validationResults.Remove(result);
        }

        public IEnumerable GetErrors(string propertyName)
        {
            return _validationResults.Where(result => result.MemberNames.Contains(propertyName));
        }

        public bool HasErrors
        {
            get { return _validationResults.Any(); }
        }

        public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
        //public event PropertyChangedEventHandler PropertyChanged;
        #endregion
    }
}
